import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';

/// 2022年更新  适配 flutter 3.0
class RatingBar01 extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return RatingBar01State();
  }
}

class RatingBar01State extends State with SingleTickerProviderStateMixin {
  ///初化函数
  /// 在Widget创建的时候
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Padding(
          child: buildCenter(),
          padding: EdgeInsets.all(20),
        ),
      ),
    );
  }

  buildCenter() {
    return RatingBar.builder(
      initialRating: 1,
      minRating: 0,
      maxRating: 5,
      direction: Axis.horizontal,
      allowHalfRating: false,
      itemCount: 5,
      itemPadding: const EdgeInsets.symmetric(horizontal: 4.0),
      itemBuilder: (context, _) => const Icon(
        Icons.star,
        color: Color(0xFFF57F17),
      ),
      //选择更新回调
      onRatingUpdate: (rating) {
        print(rating);
      },
    );
  }
}
